<?php
namespace Home\Controller;
use Think\Controller;
class LoginController extends Controller {
	public function login(){
		// $this->redirect('Login/login');
		$this->display();
	}
    
    public function dologin(){
          if(IS_POST) {
            $username = $_POST['username'];
            $pwd = $_POST['pwdLogin'];
         if(empty($username) || empty($pwd)) {
                $this->error('用户名和密码不能为空');
            }
         }
            $user = M('user');
            $where['yonghuname'] = $username;
            $where['pwd'] = $pwd;
            $arr = $user->field('id')->where($where)->find();

         if($arr) {
            $_SESSION['yonghuname'] = $username;
            $_SESSION['id'] = $arr['id'];
            $this->success('用户登陆成功',U('Home/My/my'));
             } else {
                $this->error('密码错误或者用户不存在');
         }
   
    }
    public function zhuce(){

    	$verif = new \Think\Verify();
		$yonghuname=$_POST['yonghuname'];
    	$tel=$_POST['user_name'];
    	$pwd=$_POST['pwd'];
    	$repwd=$_POST['repwd'];
    	if($pwd!=$repwd){
			$this->error('两次密码不一致');
			
		}
    	$code=$_POST['code'];
    	$time=time();
		$date=date("Y-m-d H:i:d",$time);
		$user=M('user');
		$data=array('yonghuname'=>$yonghuname,'tel'=>$tel,'pwd'=>$pwd,'addtime'=>$date);
    	if($code){
    		if($verif->check($code))  
        	{  
        		$aduser=$user->add($data); 
        		$this->success("注册成功，请重新登录");
       		 }else  
        	{  
            	$this->error("验证码错误");  
        	}  
    	}
        $this->display();
    }
 
    public function verify(){
    	
		$Verify=new \Think\Verify();
		$Verify->fontSize = 10;  
        $Verify->length   = 4;  
        $Verify->useCurve = false;  
        $Verify->codeSet = '0123456789';
        $Verify->entry(); 
	}

}